package com.service;


import com.dao.DepDAO;
import com.dao.EmpDAO;
import com.dao.IDTestDAO;
import com.dao.StudentDAO;
import com.pojo.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Set;

@Transactional
@Service
public class EmpService {

    @Autowired
    private DepDAO depDAO;

    @Autowired
    private IDTestDAO idTestDAO;

    @Autowired
    private EmpDAO empDAO;

    @Autowired
    private StudentDAO studentDAO;

    public void addEmp2()
    {
        Emp emp = new Emp();
        emp.setEmpName("新员工2");
        Dep dep = depDAO.findById(1).get();
        dep.getList().add(emp);
        empDAO.save(emp);
    }


    public void addEmp3()
    {
        Dep dep = new Dep();
        dep.setDepName("新部门");

        Emp emp1 = new Emp();
        emp1.setEmpName("新员工1");

        Emp emp2 = new Emp();
        emp2.setEmpName("新员工2");

        dep.getList().add(emp1);
        dep.getList().add(emp2);

        depDAO.save(dep);
    }

    public void printEmp()
    {
        /*Dep dep = depDAO.findById(50).get();
        List<Emp> list = dep.getList();
        for (Emp emp : list) {
            System.out.println(emp.getEmpId()+"\t"+emp.getEmpName());
        }*/
       List<Dep> list = depDAO.findByDepIdOrDepName(null,"国防部");
        System.out.println(list);

    }

    public List printCouseByStudent(int sid)
    {
        Student stu = studentDAO.findById(1).get();
        List<Course> list = stu.getCourses();
        list.stream().forEach(System.out::println);
        return list;

    }

    public void addID()
    {
        IDTest idTest = new IDTest();
        idTest.setPname("测试1");
        idTestDAO.save(idTest);
        System.out.println(idTest.getPid());
    }

}
